$(function() {
	var storage = "";
	storage = window.localStorage;
	
	
	var shops = JSON.parse(storage.getItem("shops"))
	// 获取商家名称将其显示
	var shopname = shops[shops.length-1].shopname
	console.log(shopname)
	$(".shop-name").html(shopname);
	
	// 获取数组
	var spl = shops[shops.length-1].shoplis
	// 遍历数组
	$.each(spl, function(i, e) {
		// 判断所购买的食材数量是否大于0
		if (spl[i] != null) {
			// 将数据渲染出来
			$("<div class='food'></div>").html(`<img src="` + spl[i].src + `" alt="" class="food-img">
							<span>` + spl[i].name + `×` + spl[i].num + `</span>
							<span class="money">￥` + spl[i].money + `</span>
				`).appendTo(".foods")
		}

	})
	// 渲染完毕后再渲染配送费
	$("<div class='food'></div>").html(`
				<span>配送费</span>
				<span class="money">￥3</span>
		`).appendTo(".foods")
		
	// 获取总金额将其显示
	var money = shops[shops.length-1].money+3
	$(".shop-money").html(money);
	
	// var shops = []
	// var new_shops = []
	// var shop = {}
	// shop.shopname = shopname
	// shop.shoplis = spl
	// shop.money = money
	// shops.push(shop)
	// shops.push(shop)
	// storage.setItem("shops",JSON.stringify(shops))
	// storage.setItem("shop",JSON.stringify(shop))
	// console.log(JSON.stringify(shops))
	$(".go-pay").click(function(){
		
		// var leng = shops.length-1
		// console.log(leng)
		
		// if(shops!=null){
		// 	shops[shops.length] = shop
		// 	new_shops = shops
		// 	shops.pop(shop)
		// 	new_shops.push(shop)
			
			
		// }
		// console.log(shops)
		window.location.href = "pay.html"
		// // ?index="+leng
		// storage.setItem("new_shops",JSON.stringify(new_shops))
	})
	// shops = new_shops
	// storage.setItem("shops",JSON.stringify(new_shops))
})
